package com.smqj.icu;

import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@WebServlet(name = "setParams", value = "/setParams")
public class ICUParams extends HttpServlet {

    @SneakyThrows
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
        String key = request.getParameter("key");
        String value = request.getParameter("value");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        ParameterUtil.setParameter(key,value);
        PrintWriter writer = response.getWriter();
        writer.append("OK");
    }

    @SneakyThrows
    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        String key = request.getParameter("key");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.append(ParameterUtil.getParameter(key));
    }

    public void destroy() {
    }
}
